package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-09 15:57
 */
public class Solution_0704 {
    /**
     * 二分查找
     *
     * @param nums
     * @param target
     * @return
     */
    public int search(int[] nums, int target) {
        return this.find(nums, 0, nums.length - 1, target);
    }

    public int find(int[] nums, int left, int right, int target) {
        if (right < left) return -1;
        int mid = left + right >> 1;
        if (nums[mid] < target) {
            return find(nums, mid + 1, right, target);
        } else if (nums[mid] == target) {
            return mid;
        } else {
            return find(nums, left, mid - 1, target);
        }
    }

}
